﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Twittervice.api;
using Twittervice.test;

namespace Twittervice
{
    /// <summary>
    /// Twittervice is a C# .NET Webservice that interacts with the Twitter API.
    /// </summary>
    [WebService(Namespace = "http://code.google.com/p/twittervice")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Twittervice : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        /// <summary>
        /// Retrieves the user's timeline from Twitter.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns>List of status entries</returns>
        [WebMethod]
        public List<TwitterStatus> GetFriendsTimeLine(string username, string password)
        {
            TwitterUser user = new TwitterUser(username, password);
            TwitterProvider provider = new TwitterProvider(user);

            return provider.GetFriendsTimeLine();
        }

        /// <summary>
        /// Retrieves the timeline for the specified user.
        /// </summary>
        /// <param name="requestedUser"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns>List of status entries</returns>
        [WebMethod]
        public List<TwitterStatus> GetUserTimeLine(string requestedUser, string username, string password)
        {
            TwitterUser user = new TwitterUser(username, password);
            TwitterProvider provider = new TwitterProvider(user);

            return provider.GetUserTimeLine(requestedUser);
        }

        /// <summary>
        /// Retrieves the current public timeline from Twitter.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns>List of status entries</returns>
        [WebMethod]
        public List<TwitterStatus> GetPublicTimeLine(string username, string password)
        {
            TwitterUser user = new TwitterUser(username, password);
            TwitterProvider provider = new TwitterProvider(user);

            return provider.GetPublicTimeLine();
        }

        /// <summary>
        /// Retrieves list of friends for the specified user.
        /// </summary>
        /// <param name="requestedUser"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns>List of Twitter users</returns>
        [WebMethod]
        public List<TwitterUser> GetFriendsList(String requestedUser, string username, string password)
        {
            TwitterUser user = new TwitterUser(username, password);
            TwitterProvider provider = new TwitterProvider(user);

            return provider.getFriendsList(requestedUser);
        }

        /// <summary>
        /// Retrieves list of followers of the specified user.
        /// </summary>
        /// <param name="requestedUser"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns>List of Twitter users</returns>
        [WebMethod]
        public List<TwitterUser> GetFollowersList(String requestedUser, string username, string password)
        {
            TwitterUser user = new TwitterUser(username, password);
            TwitterProvider provider = new TwitterProvider(user);

            return provider.getFollowersList(requestedUser);
        }

        /// <summary>
        /// Sends status update to Twitter.
        /// </summary>
        /// <param name="message">text of status</param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        [WebMethod]
        public void SendStatusUpdate(string message, string username, string password)
        {
            TwitterUser user = new TwitterUser(username, password);
            TwitterProvider provider = new TwitterProvider(user);

            String requestStatus = provider.UpdateStatus(message);
        }

        /// <summary>
        /// TestMethod
        /// </summary>
        [WebMethod]
        public void TestTwittervice()
        {
            TwitterStatusTest.parseXmlTest();
        }
    }
}
